var api = require('../../utils/api.js');
var app = getApp();
Page({
    /**
     * 页面的初始数据
     */
    data: {
        info:[]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

    },

    onShow(){
        this.getworkerinfo();
    },

    getworkerinfo(){
        var that=this;

        api.post({
            url: 'worker/getinfo',
            data: {},
            success: data => {
                that.setData({
                    avatar:data.data.avatar,
                    mobile:data.data.mobile,
                    name:data.data.name,
                    hsp:data.data.hsp
                })

            }
        })

    },
    chooseImage(){
        let that = this;
        var usrl=api.HOST;

        wx.chooseMedia({
          count: 1,
          mediaType:['image'],
          success: function (res) {
            let tempFilePaths = res.tempFiles;
         
            wx.uploadFile({
              filePath: tempFilePaths[0].tempFilePath,
              name: 'file',
              url: usrl+'common/upload',
              formData:{},
              success:function(res){
                var data= JSON.parse(res.data);
                    that.setData({
                        avatar:data.data.fullurl
                    });
        
              },
              fail: function (res) {
                console.log('上传失败');
                }
            })
          }
        })
    },
    getvalue(ret){
        this.setData({
            name:ret.detail.value
        })
    },
    getmobile(ret){
        this.setData({
            mobile:ret.detail.value
        })
    },

    gethosp(ret){
        this.setData({
            hsp:ret.detail.value
        })
    },
    submits(){

        var avatar=this.data.avatar;
        var mobile=this.data.mobile;
        var name=this.data.name;
        var hsp=this.data.hsp;

        var that=this;

        api.post({
            url: 'worker/setinfo',
            data: {avatar:avatar,mobile:mobile,name:name,hsp:hsp},
            success: data => {
                console.log(data);
                wx.showToast({
                  title: data.msg,
                  icon:'none'
                })

            }
        })



    }
})